from django.test import TestCase
from qiniu import Auth, put_file, etag
import qiniu.config
from MD_django.settings import BASE_DIR
# Create your tests here.
def pull_qiniu(pic_name):
    access_key = 'LYyYQzkYNdzswDd84W0m5z5YzBMBDVaOziK8EbKO'
    secret_key = '2Cejvu_Ab3MRnZrm3ZAsJZK46EAz-5yxKWQL5lh9'
    q = Auth(access_key, secret_key)
    bucket_name = 'djangol'
    key = pic_name
    # 上传文件到七牛后， 七牛将文件名和文件大小回调给业务服务器。
    policy = {
        'callbackUrl': 'http://your.domain.com/callback.php',
        'callbackBody': 'filename=$(fname)&filesize=$(fsize)'
    }
    token = q.upload_token(bucket_name, key, 3600, policy)
    localfile = BASE_DIR+"/"+pic_name
    ret, info = put_file(token, key, localfile)
    print(info)


if __name__ == '__main__':
    name="s诱惑1.jpg"
    pull_qiniu(name)